using CMS.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CMS.EFCore.Config;

public class ArticleConfig : IEntityTypeConfiguration<Article>{
    public void Configure(EntityTypeBuilder<Article> builder) {
        builder.Property(a => a.KeyWords).HasMaxLength(500).IsRequired();
        builder.Property(a => a.TitleType).HasMaxLength(200).IsRequired();
        builder.Property(a => a.Title).HasMaxLength(100).IsRequired();
        builder.Property(a => a.FullTitle).HasMaxLength(200).IsRequired();
        builder.Property(a => a.Intro).HasMaxLength(500).IsRequired();
        builder.Property(a => a.TitleFontColor).HasMaxLength(50).IsRequired();
        builder.Property(a => a.TitleFontType).HasMaxLength(50).IsRequired();
        builder.Property(a => a.ArticleContent).IsRequired();
        builder.Property(a => a.Author).HasMaxLength(20).IsRequired();
        builder.Property(a => a.Origin).HasMaxLength(100).IsRequired();
        builder.Property(a => a.PhotoUrl).HasMaxLength(500).IsRequired();
        builder.Property(a => a.Hits).HasDefaultValue(0);
// 一个类别下面多篇文章
        builder.HasOne<ArticleCategory>(c => c.ArticleCategory).WithMany(a => a.Articles).IsRequired().HasForeignKey(a=>a.ArticleCategoryId);
    }
}